<template>
  <div id="mapArea">
  <div id="company"></div>
    <div id="modeSelect" :class="[show ? 'active' : 'hidden']">
      <div id="header">
        <div id="close">X</div>
      </div>
      <section id="click">容器整体破裂； 闪火E类；</section>
      <section>容器整体破裂； 闪火D类；</section>
      <section>容器整体破裂； 闪火A类；</section>
      <section>容器整体破裂； 云爆；</section>
      <section>容器整体破裂； 云爆；</section>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, reactive, toRefs } from "vue";
//
// czm
import * as Cesium from "cesium";
import { explosionViewer, addBox, entityPicker, explosion , building,fire} from "../../util";
import removeExplosion from "../../util/CesiumUtil/removeExplosion";

export default defineComponent({
  setup() {
    const data = reactive({
      show: false,
    });

    const refData = toRefs(data);
    onMounted(() => {
      const viewer = explosionViewer("mapArea");

      building.forEach((e)=>{
        addBox({
          coordinates: Cesium.Cartesian3.fromDegreesArrayHeights(e.bbox),
          height: e.height,
          viewer: viewer,
          identifier: e.identifier,
          show:true,
          alpha: 0.8
        })
      });

      entityPicker({
        viewer: viewer,
        canvasX: 0,
        canvasY: 0,
      });


      fire.forEach((e)=>{
        viewer.entities.add({
        name: "fire",
        position: Cesium.Cartesian3.fromDegrees(
          e.coordinate[0],
          e.coordinate[1],
          e.coordinate[2]
        ),
        billboard: {
          image: "./fire.png",
          scaleByDistance: new Cesium.NearFarScalar(50, 1.2, 100, 0.1),
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 500),
        },
      });
      })

      const handle = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
      let position: Cesium.Cartesian3
      handle.setInputAction((e) => {
        const cartesian2 = e.position;
        const pick = viewer.scene.pick(cartesian2);
        if (Cesium.defined(pick) && pick.id.name == "fire") {
          data.show = !data.show;
          position = pick.primitive._actualPosition;
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

      const click = document.getElementById("click") as HTMLElement;
      click.onclick = () => {
        explosion(
          viewer,
          position,
          186,
          126
        );
      };

      const close = document.getElementById("close") as HTMLElement;
      close.onclick = () => {
        data.show = !data.show;
        removeExplosion(viewer);
      }
    });
    return { ...refData };
  },
});
</script>

<style lang="less">
#mapArea {
  height: 100%;
  width: 100%;
  #modeSelect {
    height: 200px;
    width: 500px;
    background-color: rgba(0, 20, 35, 0.65);
    position: absolute;
    top: 50%;
    right: 50px;
    z-index: 99;
    transform: translateY(-50%);
    box-shadow: inset 10px 30px 40px #04e4e45e, inset -10px -10px 40px #04e4e45e;
    #header {
      height: 20px;
      #close{
        height: 20px;
        width: 20px;
        float: right;
        margin-right: 10px;
        cursor: pointer;
        &:hover{
          background-color: rgb(6, 197, 245);
        }
      }
    }
    section {
      height: 20px;
      margin-top: 10px;
      margin-left: 10px;
      color: aqua;
      cursor: pointer;
      &:hover{
        background-color: rgb(6, 197, 245);
      }
    }
  }
}
.active {
  display: block;
}
.hidden {
  display: none;
}
</style>
